#include "helper_icons.h"

namespace Helper
{

    const unsigned char *getIcon(String name, int size)
    {
        typedef std::map<String, const unsigned char *> TYPE_ICONS_MAP;
        TYPE_ICONS_MAP iconsMap;

#pragma region init iconsMap.weather
        iconsMap["01d@128"] = weather_128_01d;
        iconsMap["01n@128"] = weather_128_01n;
        iconsMap["02d@128"] = weather_128_02d;
        iconsMap["02n@128"] = weather_128_02n;
        iconsMap["03d@128"] = weather_128_03d;
        iconsMap["03n@128"] = weather_128_03n;
        iconsMap["04d@128"] = weather_128_04d;
        iconsMap["04n@128"] = weather_128_04n;
        iconsMap["09d@128"] = weather_128_09d;
        iconsMap["09n@128"] = weather_128_09n;
        iconsMap["10d@128"] = weather_128_10d;
        iconsMap["10n@128"] = weather_128_10n;
        iconsMap["11d@128"] = weather_128_11d;
        iconsMap["11n@128"] = weather_128_11n;
        iconsMap["13d@128"] = weather_128_13d;
        iconsMap["13n@128"] = weather_128_13n;
        iconsMap["50d@128"] = weather_128_50d;
        iconsMap["50n@128"] = weather_128_50n;

        iconsMap["01d@32"] = weather_32_01d;
        iconsMap["01n@32"] = weather_32_01n;
        iconsMap["02d@32"] = weather_32_02d;
        iconsMap["02n@32"] = weather_32_02n;
        iconsMap["03d@32"] = weather_32_03d;
        iconsMap["03n@32"] = weather_32_03n;
        iconsMap["04d@32"] = weather_32_04d;
        iconsMap["04n@32"] = weather_32_04n;
        iconsMap["09d@32"] = weather_32_09d;
        iconsMap["09n@32"] = weather_32_09n;
        iconsMap["10d@32"] = weather_32_10d;
        iconsMap["10n@32"] = weather_32_10n;
        iconsMap["11d@32"] = weather_32_11d;
        iconsMap["11n@32"] = weather_32_11n;
        iconsMap["13d@32"] = weather_32_13d;
        iconsMap["13n@32"] = weather_32_13n;
        iconsMap["50d@32"] = weather_32_50d;
        iconsMap["50n@32"] = weather_32_50n;

        iconsMap["01d@24"] = weather_24_01d;
        iconsMap["01n@24"] = weather_24_01n;
        iconsMap["02d@24"] = weather_24_02d;
        iconsMap["02n@24"] = weather_24_02n;
        iconsMap["03d@24"] = weather_24_03d;
        iconsMap["03n@24"] = weather_24_03n;
        iconsMap["04d@24"] = weather_24_04d;
        iconsMap["04n@24"] = weather_24_04n;
        iconsMap["09d@24"] = weather_24_09d;
        iconsMap["09n@24"] = weather_24_09n;
        iconsMap["10d@24"] = weather_24_10d;
        iconsMap["10n@24"] = weather_24_10n;
        iconsMap["11d@24"] = weather_24_11d;
        iconsMap["11n@24"] = weather_24_11n;
        iconsMap["13d@24"] = weather_24_13d;
        iconsMap["13n@24"] = weather_24_13n;
        iconsMap["50d@24"] = weather_24_50d;
        iconsMap["50n@24"] = weather_24_50n;

#pragma endregion

#pragma region init iconsMap.other
        iconsMap["wifi_error@256"] = icon_wifi_error_256;
        iconsMap["warning@256"] = icon_warning_256;

        iconsMap["humi@24"] = icon_humi_24;
        iconsMap["temp@24"] = icon_temp_24;
        iconsMap["wind@24"] = icon_wind_24;
        iconsMap["press@24"] = icon_press_24;
        iconsMap["home_humi@24"] = icon_home_humi_24;
        iconsMap["home_temp@24"] = icon_home_temp_24;
#pragma endregion

        char iconKeyChar[20];
        snprintf(iconKeyChar, sizeof(iconKeyChar), "%s@%d", name.c_str(), size);
        String iconKey(iconKeyChar);
        TYPE_ICONS_MAP::iterator iconIter = iconsMap.find(iconKey);

        if (iconIter == iconsMap.end())
        {
            Serial2.printf("icon not find: %d \n", iconKeyChar);
            return weather_not_found;
        }
        else
        {
            return iconIter->second;
        }
    }

}
